/**
 * @(#) AddressProxy.as
 *
 * @date		2009. 02. 18.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 주소변경 - Proxy
 * 				
 */
package com.skt.common_hr.myprofile.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.myprofile.model.vo.CareerVO;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class CareerProxy extends CommonProxy
	{
		public static const NAME:String = "CareerProxy";
		
		public static const LOAD_CAREER_COMPLETE:String = "loadCareerComplete";
		public static const LOAD_CAREER_FAILED:String 	= "loadCareerFailed";
		public static const SAVE_CAREER_COMPLETE:String = "saveCareerComplete";
		public static const SAVE_CAREER_FAILED:String 	= "saveCareerFailed";

		public var careerList:ArrayCollection;
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function CareerProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		
		
		public function load(pernr:String):void
		{
			var params:Object = new Object();
			params["I_PERNR"] = pernr;
			params["I_ACTIO"] = "DIS";
						
			loadData("Z_HR_0118",params, result, fault); 
		}
		
		/**
		 * 주소를 저장함
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param   pernr: 사번
		 * 			PSTLZ: 우편번호
		 * 			LOCAT: 상세주소
		 * 			SUBTY: 주소 구분 (1-본적, 2-현주소, 3-주민등록주소)
		 * @return void
		 */
		public function save(pernr:String, arr:Array):void
		{
			var params:Object = new Object();
			params["I_PERNR"] = pernr;
			params["I_ACTIO"] = "INS";
			
			var table:Object = new Object();
			table["T_IN"] = arr;
			
			saveData("Z_HR_0118", params, table, resultSave, faultSave); 
		}



		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {
				careerList = parseCareerList(event.result.T_OUT);
				facade.sendNotification(LOAD_CAREER_COMPLETE, this);
			}
			else {
				facade.sendNotification(LOAD_CAREER_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(LOAD_CAREER_FAILED, this);
		}
		
		
		public function resultSave(event:ResultEvent):void
		{
			if(retCode==0) {
				facade.sendNotification(SAVE_CAREER_COMPLETE, this);
			}
			else {
				facade.sendNotification(SAVE_CAREER_FAILED, this);
			}
		}
		
		private function faultSave(event:FaultEvent):void
		{
			facade.sendNotification(SAVE_CAREER_FAILED, this);
		}
		
		
		
		private function parseCareerList(src:ArrayCollection):ArrayCollection
		{
			var careerList:ArrayCollection = new ArrayCollection();
			for each (var item:Object in src)
			{
				var vo:CareerVO = new CareerVO;
				
				vo.ARBGB	=	item.ARBGB;	//BEGDA
				vo.BEGDA	=	DateUtil.stringToDateTime(item.BEGDA);	//발령 유형 이름
				vo.ENDDA	=	DateUtil.stringToDateTime(item.ENDDA);	//발령 사유 이름
				vo.SKGYNT	= 	item.SKGYNT;	//부서명(상위조직명 포함)
				vo.LSTJW	=	item.LSTJW;		//최종직위
				vo.ORT01	=	item.ORT01;		//근무지
				vo.LSTJM	=	item.LSTJM;		//최종담당업무
				/* 
				vo.CONYR	=	item.CONYR;		//경력인정기간(연)
				vo.CONMO	=	item.CONMO;		//경력인정기간(월)
				vo.SUBTY	=	item.SUBTY;		// 
				vo.SEQNR	=	item.SEQNR;		// 
				vo.OBJPS	=	item.OBJPS;		// 
				vo.SKGYN	=	item.SKGYN;		//SK그룹사 관계여부
				vo.STEXT	= 	item.STEXT;		// 부서명
				vo.MASST	=	item.MASST;		// 퇴직사유
				 */
				
				careerList.addItem(vo);
			}
			return careerList;
		}
		
		public function toJSONobject(vo:CareerVO):Object
		{
			var jsonObj:Object = new Object();
				
				jsonObj["ARBGB"]	=	vo.ARBGB;	//BEGDA
				jsonObj["BEGDA"]	=	DateUtil.toBasicString(vo.BEGDA);	//발령 유형 이름
				jsonObj["ENDDA"]	=	DateUtil.toBasicString(vo.ENDDA);	//발령 사유 이름
				jsonObj["SKGYNT"]	= 	vo.SKGYNT;	//부서명(상위조직명 포함)
				jsonObj["LSTJW"]	=	vo.LSTJW;		//최종직위
				jsonObj["ORT01"]	=	vo.ORT01;		//근무지
				jsonObj["LSTJM"]	=	vo.LSTJM;		//최종담당업무
				/* 
				jsonObj["CONYR"]	=	vo.CONYR;		//경력인정기간(연)
				jsonObj["CONMO"]	=	vo.CONMO;		//경력인정기간(월)
				jsonObj["SUBTY"]	=	vo.SUBTY;		// 
				jsonObj["SEQNR"]	=	vo.SEQNR;		// 
				jsonObj["OBJPS"]	=	vo.OBJPS;		// 
				jsonObj["SKGYN"]	=	vo.SKGYN;		//SK그룹사 관계여부
				jsonObj["STEXT"]	=	vo.STEXT;		// 부서명
				jsonObj["MASST"]	=	vo.MASST;		// 퇴직사유
 */
			return jsonObj;
		}
	}
}